package com.carl.dao;

import java.util.List;

import com.carl.bean.Menu;
import com.google.code.morphia.Datastore;
import com.google.code.morphia.Key;
import com.google.code.morphia.query.Query;


public class MenuDao extends BasicDao<Menu> {

	protected MenuDao(Datastore ds) {
		super(ds);
	}

	/**
	 * 保存一个菜单信息
	 * @param menu
	 * @return
	 */
	public Key<Menu> saveUser(Menu menu){
		Key<Menu> keyInfo = ds.save(menu);
		return keyInfo;
	};
	
	/**
	 * 查找所有的子节点菜单
	 * @param nodeId
	 * @return
	 */
	public List<Menu> findMenuByNodeId(Integer nodeId){
		Query<Menu> query = ds.createQuery(Menu.class);
		
		if(nodeId == null){
			query.filter("parentId =", -1);
		}else{
			query.filter("parentId =", nodeId);
		}
		
		return query.asList();
	}

}
